﻿using System;
using GC_FFW.BusinessEntities.Abstractions.Interfaces.Soccerfame;
using GC_FFW.Common.Constants.Text;

namespace GC_FFW.BusinessEntities.Soccerfame
{
	public class Match : IMatch
	{
		#region IMatch Members

		public IHyperlink TournamentType { get; set; }
		public DateTime Date { get; set; }
		public IHyperlink HomeTeam { get; set; }
		public IHyperlink MatchResult { get; set; }
		public IHyperlink AwayTeam { get; set; }

		public int AwayTeamGoalsCount
		{
			get
			{
				var result = 0;

				if (MatchResult != null && !string.IsNullOrWhiteSpace(MatchResult.Name)
					&& MatchResult.Name.Contains(Symbols.COLON))
				{
					int.TryParse(
						MatchResult.Name.Substring(
							MatchResult.Name.LastIndexOf(Symbols.COLON, StringComparison.Ordinal) + 1).Trim(),
						out result);
				}

				return result;
			}
		}

		public int HomeTeamGoalsCount
		{
			get
			{
				var result = 0;

				if (MatchResult != null && !string.IsNullOrWhiteSpace(MatchResult.Name)
					&& MatchResult.Name.Contains(Symbols.COLON))
				{
					int.TryParse(
						MatchResult.Name.Substring(
							0,
							MatchResult.Name.LastIndexOf(Symbols.COLON, StringComparison.Ordinal) - 1).Trim(),
						out result);
				}

				return result;
			}
		}

		#endregion
	}
}
